package com.wef.demo.service.impl;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.gfa4j.hibernate.BaseObject;
import com.gfa4j.service.impl.BaseServiceImpl;
import com.wef.demo.entity.StudentSubject;
import com.wef.demo.entity.domain.StudentSubjectDomain;
import com.wef.demo.service.StudentSubjectService;

public class StudentSubjectServiceImpl extends BaseServiceImpl implements StudentSubjectService {

	public StudentSubject loadStudentSubjectById(String studentSubjectId) {
		return (StudentSubject) super.loadByPK(StudentSubject.class, StudentSubjectDomain.studentSubjectId, studentSubjectId);
	}

	public StudentSubject addStudentSubject(StudentSubject studentSubject) {
		studentSubject = (StudentSubject) super.saveObject(studentSubject);
		return studentSubject;
	}

	public StudentSubject updateStudentSubject(StudentSubject studentSubject) {
		return (StudentSubject) super.updateObject(studentSubject);
	}

	public void removeStudentSubject(StudentSubject studentSubject) {
		this.deleteObject(studentSubject);
	}

	public StudentSubject saveOrUpdateStudentSubject(StudentSubject studentSubject) {
		if (studentSubject.getRowStatus() == BaseObject.ROWSTATUS_ADDED) {
			return this.addStudentSubject(studentSubject);
		}
		if (studentSubject.getRowStatus() == BaseObject.ROWSTATUS_MODIFIED) {
			return this.updateStudentSubject(studentSubject);
		}
		if (studentSubject.getRowStatus() == BaseObject.ROWSTATUS_DELETED) {
			this.removeStudentSubject(studentSubject);
		}
		return studentSubject;
	}

	public Collection<StudentSubject> saveOrUpdateStudentSubjects(Set<StudentSubject> entitys) {
		Set<StudentSubject> retStudentSubjects = new HashSet<StudentSubject>();
		for (StudentSubject entity : entitys) {
			retStudentSubjects.add(saveOrUpdateStudentSubject(entity));
		}
		return retStudentSubjects;
	}
}